<template>
    <div class="body_background" :style="GetWindowBackground">
        <div class="body_background">
            <ul class="top-nav-box">
                <li v-for="(item,index) in navList" :key="item.id"
                    @click="navClickFun(index)"
                >
                    <div class="type-name">
                        {{item.name}}
                        <i :class="index==1?'display-block':'display-none'" class="circular"></i>
                    </div>
                    <div :class="typeIndex==index?'active':'no_active'">&nbsp;</div>
                </li>
            </ul>
            <ul class="order-list-box">
                <li>
                    <router-link to="/ShopOrderDetail?id=1&name='张三'">
                        <div class="order-top-box second-color middle-font-size">
                            <div>2021-05-08 12:12:12</div>
                            <div>待支付</div>
                        </div>
                        <div class="type small-font-size main-color">总部直供</div>
                        <div class="order-content-box" v-for="(item,index) in goodsObj.item" :key="item.id">
                            <img :src="item.imgUrl"/>
                            <div class="order-info-box">
                                <div class="main-color big-font-size">{{item.id}}--{{item.title}}</div>
                                <div class="three-color small-font-size">肉厚多汁</div>
                                <div class="price-color">￥20</div>
                            </div>
                            <div class="light-color small-font-size goods-count">X 1</div>
                        </div>
                    </router-link>
                    <!--更多-->
                    <div :class="goodsObj.show==true?'display-block':'display-none'">
                        <div class="order-content-box"
                             v-for="(item,index) in goodsObj.more"
                             :key="item.id"
                        >
                            <img :src="item.imgUrl"/>
                            <div class="order-info-box">
                                <div class="main-color big-font-size">{{item.id}}--{{item.title}}</div>
                                <div class="three-color small-font-size">肉厚多汁</div>
                                <div class="price-color">￥20</div>
                            </div>
                            <div class="light-color small-font-size goods-count">X 1</div>
                        </div>
                    </div>
                    <div class="more-box" @click="lookMoreOrder">
                        <div class="main-color small-font-size">查看更多</div>
                        <img src="../../assets/img/arrow.png" :class="goodsObj.show==true?'active-up':''">
                    </div>
                    <div class="small-font-size three-color order-item-price">共3件商品&nbsp;&nbsp;总金额<span
                            class="price-color">￥300</span>
                    </div>
                    <div class="order-operation-box">
                        <div class="small-font-size second-color">一小时后订单关闭</div>
                        <div class="order-operation-button">
                            <mt-button plain type="primary"
                                       size="small"
                                       @click.native="cancelClickFun"
                                       class="green-color green-border"
                            >取消</mt-button>
                            <mt-button plain type="primary"
                                       size="small"
                                       @click.native="goPayFun"
                                       class="background white-color green-border"
                            >立即支付</mt-button>
                        </div>
                    </div>
                </li>
            </ul>
            <div class="seize-seat light-color">-- 没有数据了 --</div>
        </div>
        <!--支付弹框-->
        <div class="pay-box" v-if="payHidden==true">
            <div class="pay-close" @click="closePayFun">&times;</div>
            <div class="pay-title main-color">确认支付</div>
            <div class="main-color pay-price">￥3000</div>
            <!--<div class="pay-item">-->
            <!--<div class="second-color">支付方式：</div>-->
            <!--<div class="pay-arrow-box">-->
            <!--<div class="align-left three-color">货款支付(余额:￥5)</div>-->
            <!--<img src="../../assets/img/arrowFlag.png" class="arrow-img">-->
            <!--</div>-->
            <!--</div>-->
            <input v-model="pay_password" type="password" class="pay-all-price" placeholder="请输入支付密码">
            <mt-button class="background pay-button" @click="truePayFun">确认支付</mt-button>
        </div>
        <!--弹框背景-->
        <div class="backdrop" :class="payHidden==true?'display-block':''"></div>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui';

    export default {
        name: "ShopOrderList",
        data() {
            return {
                navList: [
                    {
                        id: 1,
                        name: '全部'
                    }, {
                        id: 2,
                        name: '待支付'
                    }, {
                        id: 3,
                        name: '已完成'
                    }, {
                        id: 4,
                        name: '已取消'
                    }],
                typeIndex: 0,//顶部类型索引
                pay_password:'',
                GetWindowBackground: {
                    'min-height': ''
                },
                orderLen: 3,
                goodsList: [
                    {
                        id: 1,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 2,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 3,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 4,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 5,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }
                ],
                goodsObj: {},
                payHidden:false,//支付弹框 false:隐藏  true:显示
            }
        },
        mounted() {
            this.goodsNewArray();
        },
        methods: {

            //确认支付
            truePayFun(){
                this.payHidden=false
            },
            //关闭支付弹框
            closePayFun() {
                this.payHidden = false
            },
            //重组数组
            goodsNewArray() {
                var old_arr = this.goodsList;
                var new_obj = {};
                var arr = []
                var more = []
                if (old_arr.length < 2) {
                    arr = old_arr
                } else {
                    for (var i = 0; i < old_arr.length; i++) {
                        var item = old_arr[i]
                        if (i < 2) {
                            arr.push({
                                id: item.id,
                                title: item.title,
                                imgUrl: item.imgUrl
                            })
                        } else {
                            more.push({
                                id: item.id,
                                title: item.title,
                                imgUrl: item.imgUrl
                            })
                        }
                    }
                }
                new_obj.item = arr;
                new_obj.more = more;
                new_obj.show = false;
                console.log(new_obj)
                this.goodsObj = new_obj
            },
            //顶部导航切换
            navClickFun(index) {
                this.typeIndex = index
            },
            //查看更多订单
            lookMoreOrder(item) {
                this.goodsObj.show = !this.goodsObj.show
            },
            //取消
            cancelClickFun() {
                Toast('取消');
            },
            //去支付
            goPayFun(){
                this.payHidden=true
            },
            getHeight() {
                // 获取浏览器高度
                this.GetWindowBackground['min-height'] = window.innerHeight + 'px'
            },
        },
        // 生命周期 - 创建完成（可以访问当前this实例）
        created() {
            window.addEventListener('resize', this.getHeight) // 注册监听器
            this.getHeight() // 页面创建时先调用一次
        },
        // 生命周期 - 销毁完成
        destroyed() {
            window.removeEventListener('resize', this.getHeight)
        },
    }
</script>

<style lang="scss" scoped>
    .top-nav-box {
        width: 100%;
        height: 40px;
        overflow-x: auto;
        display: flex;
        padding-top: 5px;
        background: #fff;
        li {
            width: 25%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            font-size: 15px;
            .type-name{
                position: relative;
            }
            .circular{
                width: 8px;
                height: 8px;
                background: #ffd000;
                border-radius: 50%;
                position: absolute;
                top: -5px;
                right: -5px;
            }
        }
        .no_active {
            width: 15px;
            height: 2px;
            margin-top: 3px;
            background: #fff;
        }
        .active {
            width: 15px;
            height: 2px;
            margin-top: 3px;
            background: #05c569;
        }
    }

    .order-list-box {
        width: calc(100% - 20px);
        height: auto;
        margin: 10px 10px 0 10px;
        li {
            width: calc(100% - 30px);
            background: #fff;
            padding: 0 15px;
            margin-bottom: 10px;
            border-radius: 4px;
            .type {
                width: 100%;
                text-align: left;
                padding-bottom: 5px;
            }
            .order-top-box {
                width: 100%;
                height: 35px;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
            .order-content-box {
                width: 100%;
                display: flex;
                padding: 7px 0;
                img {
                    width: 60px;
                    height: 60px;
                    margin-right: 10px;
                    border-radius: 1px;
                }
                .order-info-box {
                    width: calc(100% - 110px);
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    text-align: left;
                }
                .goods-count {
                    margin-top: auto;
                    margin-left: auto;
                }
            }
            .more-box {
                width: 100%;
                text-align: left;
                display: flex;
                align-items: center;
                margin: 8px 0;
                img {
                    width: 10px;
                    height: 6px;
                    margin: 0 5px;
                }
                .active-up {
                    transform: rotate(180deg);
                    -webkit-transform: rotate(180deg);
                    -moz-transform: rotate(180deg);
                }
            }
            .order-operation-box {
                width: 100%;
                min-height: 40px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-top: 1px dashed #D2D6DC;
                padding: 5px 0;
            }
            .order-item-price {
                width: 100%;
                display: block;
                text-align: right;
                margin-bottom: 10px;
            }

        }
    }

    .mint-button--primary.is-plain {
        border: 1px solid #b1b5d9;
        background-color: transparent;
        color: #b1b5d9;
        margin-left: 8px;
    }

    .mint-button--small {
        display: inline-block;
        padding: 0 10px;
        height: 26px;
    }

</style>